/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import dto.Conference;
import dto.Conferenceitem;
import dto.ConferenceitemId;
import dto.User;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import model.ConferenceListDisplayModel;
import model.ConferenceModel;
/**
 *
 * @author Gary
 */
public class ParticipateAction  extends ActionSupport{
    private Conference conference;
    private String conferenceName;
    private List<Conferenceitem> items;
    private List<Conferenceitem> bookedItems;
    private String bookItemName;
    private String payitems;
    private double amount = 0.00;

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public String getPayitems() {
        return payitems;
    }

    public void setPayitems(String payitems) {
        this.payitems = payitems;
    }
    public String getBookItemName() {
        return bookItemName;
    }
    public void setBookItemName(String bookItemName) {
        this.bookItemName = bookItemName;
    }
    public List<Conferenceitem> getBookedItems() {
        return bookedItems;
    }
    public void setBookedItems(List<Conferenceitem> bookedItems) {
        this.bookedItems = bookedItems;
    }
    public List<ConferenceListDisplayModel> getBookedDisplayItems() {
        return bookedDisplayItems;
    }
    public void setBookedDisplayItems(List<ConferenceListDisplayModel> bookedDisplayItems) {
        this.bookedDisplayItems = bookedDisplayItems;
    }
    private List<ConferenceListDisplayModel> displayItems; 
    private List<ConferenceListDisplayModel> bookedDisplayItems;
    public List<ConferenceListDisplayModel> getDisplayItems() {
        return displayItems;
    }
    public void setDisplayItems(List<ConferenceListDisplayModel> displayItems) {
        this.displayItems = displayItems;
    }
    public List<Conferenceitem> getItems() {
        return items;
    }
    public void setItems(List<Conferenceitem> items) {
        this.items = items;
    }
    public String getConferenceName() {
        return conferenceName;
    }
    public void setConferenceName(String conferenceName) {
        this.conferenceName = conferenceName;
    }
    public Conference getConference() {
        return conference;
    }
    public void setConference(Conference conference) {
        this.conference = conference;
    }
    public ParticipateAction() {
    }  
    public String execute() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    public String toParticipate() throws Exception {
        if (conferenceName != null && conferenceName.length() > 0) {
           conference = new Conference(conferenceName, "Siminar", "Sands Hotel", true, null, true, 99.90,128);
        } else {
            String conferenceNameInSession = ActionContext.getContext().getSession().get("ParticipateConference")==null ? null : ActionContext.getContext().getSession().get("ParticipateConference").toString();
            conference = new Conference(conferenceNameInSession, "Siminar", "Sands Hotel", true, null, true, 99.90,128);
        }
        return "showpage";
    }
     // get conference and list the items of the conference
    public String listItem(){
        // dummy data
        conference = new Conference(conferenceName, "Siminar", "Sands Hotel", true, null, true, 99.90, 128);
        items = new ArrayList<Conferenceitem>();
        ConferenceitemId id  = new ConferenceitemId(this.conferenceName,"Item1");
        items.add(new Conferenceitem(id,"Item Desc 1",1,"sb.html",1,(double)10,false));
        id  = new ConferenceitemId(this.conferenceName,"Item2");
        items.add(new Conferenceitem(id,"Item Desc 2",2,"sb.html",2,(double)20,false));
        id  = new ConferenceitemId(this.conferenceName,"Item3");
        items.add(new Conferenceitem(id,"Item Desc 3",3,"sb.html",3,(double)30,false));
        displayItems = ConferenceModel.ConverModelList(items);
        bookedDisplayItems = ConferenceModel.ConverModelList(items);
        return "itemlist";
    }
    public String bookitem(){
        User currentUser = ActionContext.getContext().getSession().get("CurrentUser")==null ? null : (User)ActionContext.getContext().getSession().get("CurrentUser");
        if (currentUser == null) {
            return "login";
        }
        System.out.println(conferenceName + bookItemName);
        return "itembooked";
    }
    public String topayitems()
    {
        System.out.print(payitems);
        System.out.print(conferenceName);
        List<String> itemnamesroot = Arrays.asList(payitems.split("&"));
        List<String> itemnames = new ArrayList<String>();
        for (String name : itemnamesroot) {
            String newname = name.replace("&", "");
            if (newname.length() > 0) {
                 itemnames.add(newname);
            }        
        }
        // dummy data, put to pay items in items arraylist
         conference = new Conference(conferenceName, "Siminar", "Sands Hotel", true, null, true, 99.90, 128);
        items = new ArrayList<Conferenceitem>();
        ConferenceitemId id  = new ConferenceitemId(this.conferenceName,"Item1");
        items.add(new Conferenceitem(id,"Item Desc 1",1,"sb.html",1,(double)10,false));
        id  = new ConferenceitemId(this.conferenceName,"Item2");
        items.add(new Conferenceitem(id,"Item Desc 2",2,"sb.html",2,(double)20,false));
        id  = new ConferenceitemId(this.conferenceName,"Item3");
        items.add(new Conferenceitem(id,"Item Desc 3",3,"sb.html",3,(double)30,false));
        displayItems = ConferenceModel.ConverModelList(items);
        for(Conferenceitem item : items)
        {
            amount += item.getSellPrice();
        }
        return "topayitems";
    }
    
     public String topayconference()
    {
        System.out.print(conferenceName);
        // dummy data, put to pay items in items arraylist
         conference = new Conference(conferenceName, "Siminar", "Sands Hotel", true, null, true, 99.90, 128);
        return "topayconference";
    }
    
    public String participate()
    {
        System.out.println(conferenceName);
        User currentUser = ActionContext.getContext().getSession().get("CurrentUser")==null ? null : (User)ActionContext.getContext().getSession().get("CurrentUser");
        if (currentUser == null) {
            return "login";
        }
        return "participated";
    }
}
